<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8
 * Time: 23:13
 */

namespace app\api\Model;


class Product extends BaseModel
{
    protected $hidden = ['create_time', 'update_time'];

    public function getMainImgUrlAttr($value, $data)
    {
        return $this->prefixImgUrl($value, $data);
    }

//    public function imgs()
//    {
//        return $this->hasMany('ProductImage', 'product_id', 'id');
//    }
//
//    public function properties(){
//       return $this->hasMany('ProductProperty','product_id','id');
//    }

    public static function getMostRecent($count)
    {
        $products = self::limit($count)->order('create_time desc')->select();
        return $products;
    }

    public static function getProductsByCategoryTD($categoryID)
    {
//        var_dump($categoryID);
//        die;
        $product = self::where('cate_id', $categoryID)
            ->select();
//        var_dump($product);
//        die;
        return $product;
    }

    public static function getProductDetail($id){

        //Query
        $product = self::where('id', $id)
            ->find();
        return $product;
    }


}